<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Cart;
use DB;
use App\Model\User;
class addCartListController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
       
         //取到用户登陆uid
        $uid = session('homeInfo')->id;

        //取到购物车里的所有参数 下一页面需要商品名字和数量
        $cart = Cart::instance($uid)->content();
       
      
        //统计购物车
        $count = Cart::instance($uid)->count();

        //商品总价格-->下一页面需要价钱
        $sub = Cart::instance($uid)->subtotal();
       

        //购物车里有MID 商家ID

        //$dianming = DB::table('merchant')->where('id',$uid)->select('name')->get();

        //取到用户名和电话
        $user = User::find($uid);

        //购物车列表页
        return view('home.showAddList',['cart'=>$cart,'count'=>$count,'sub'=>$sub,'user'=>$user]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($rowId)
    {
        //取到用户uid
       $uid = session('homeInfo')->id;
 
       Cart::instance($uid)->remove($rowId);
       return redirect('/');
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
